﻿using AdminStyem.Application.Command.SlaughterCommand;
using AdminStyem.Application.DTO;
using AdminStyem.Domain.Entity.Boss;
using AdminStyem.Repositories;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdminStyem.Application.CommandHandler.SlaughterCommandHandler
{
    public class SlaughteringfirmShowCommandHandler : IRequestHandler<SlaughteringfirmShowCommand, APIResult<List<SlaughteringfirmDTO>>>
    {
        IBaseRespository<Slaughteringfirm> BaseSlaugfirm;

        public SlaughteringfirmShowCommandHandler(IBaseRespository<Slaughteringfirm> baseSlaugfirm)
        {
            BaseSlaugfirm = baseSlaugfirm;
        }

        public async Task<APIResult<List<SlaughteringfirmDTO>>> Handle(SlaughteringfirmShowCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<SlaughteringfirmDTO>> ret = new APIResult<List<SlaughteringfirmDTO>>();
            var firms = await BaseSlaugfirm.GetAll();
            ret.Data = firms.Select(f => new SlaughteringfirmDTO
            {
                SlaughteringfirmId = f.SlaughteringfirmId,
                FirmName = f.FirmName,
                Province = f.Province,
                City = f.City,
                County = f.County,
                FirmAddr = f.FirmAddr,
                FirmTime = f.FirmTime,
                FirmContext = f.FirmContext,
                FirmPhoto = f.FirmPhoto,
                IsDeleted = f.IsDeleted
            }).ToList();
            ret.Code = ResultCode.查询成功;
            ret.Message = ResultCode.查询成功.ToString();
            return ret;
        }
    }
}
